package com.car.action.api;

import java.util.List;
import java.util.Map;

import com.car.common.model.Card;
import com.car.common.model.CardDiscuss;
import com.car.common.model.Users;
import com.jfinal.core.Controller;
import com.utils.JwtToken;
import com.utils.StringUtil;

public class SharesController extends Controller{

	public void index() {
		String card_id = getPara("card_id");
		Map<String,Object> cardData = Card.dao.sel_one(card_id, 0L);
		String content = StringUtil.decode(String.valueOf(cardData.get("content"))); 
		List<Map<String,Object>> discussList = CardDiscuss.dao.sel_list(getPara("card_id"), 1);
		setAttr("card", cardData);
		setAttr("title",    content.length() < 20 ? content : content.substring(0, 20));
		setAttr("discuss_list", discussList);
		render("index.html");
	}
	
	public void download() {
		render("download.html");
	}
	
	
	public void login() {
		render("login.html");
	}
	
	
	public void apply_out() {
		String token = getPara("token");
		Long user_id = 0L;
		try {
			if (StringUtil.empty(token)) {
			} else {
				user_id = JwtToken.getAppUID(token);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (user_id > 0L) {
			Users users = Users.dao.findById(user_id);
			setAttr("free_hot", users.getFreeHot());
		}
		setAttr("token", token);
		render("apply_out.html");
	}
	
}
